import React from 'react';
import {View} from 'react-native';
import {getWorkstation} from '../../api';
import PublicHead from '../publicComponents/PublicHead';
import StationTab from './StationTab';
import TabView from './TabView';

/**
 * 工作站
 */
class Workstation extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      index: 0,
      workstation: [],
    };
    this.upData();
  }

  upData = (index = 0) => {
    getWorkstation()
      .then(res => {
        this.setState({index, workstation: res.data});
      })
      .catch(err => {
        console.log(err);
      });
  };

  render() {
    return (
      <View>
        <PublicHead headerText={'工作站'}/>
        <StationTab data={this.state.workstation} upData={this.upData}/>
        <TabView {...this.state.workstation[this.state.index]} />
      </View>
    );
  }
}

export default Workstation;
